MODULE = PlPN          PACKAGE = PlPN::SearchOptions

#
# Pod::Html is kind of brain-dead:
#
# Place Z<> between function names and parentheses, otherwise Pod::Html
# assumes you meant to put C<...> around it
#
# Put explicit text in all links L<use my text, stupid|some::perl::module>,
# otherwise Pod::Html assumes you want "the X manpage". (Does not apply to
# relative links withing this file.)
#
# It also assumes you want a link if you have C<...> with text matching a
# potential link target. The only way I've found around that is to split it
# up into multiple pieces: C<wo>C<rd>. Looks correct in the resulting HTML,
# but it's ugly to have <code>wo</code><code>rd</code> in the source, and I
# shouldn't have to do it.
#

=head1 NAME

PlPN::SearchOptions - The search options object

=head1 SYNOPSIS

	use PlPN qw(PN :EFIFFileSet :EFindWhere);
	
	my $uso = PN->GetUserSearchOptions;
	$uso->UseRegExp(1);
	$uso->FindText($pattern);
	PN->FindInFiles($uso);
	
	# etc.

=head1 DESCRIPTION

Allows setting of search options from Perl.

=cut

FALLBACK: TRUE

bool
eq(a,b,swap)
		extensions::ISearchOptions* a;
		extensions::ISearchOptions* b;
		IV swap;
	OVERLOAD: ==
	CODE:
		RETVAL = (a == b);
	OUTPUT:
		RETVAL

#
# xsubpp only generates the following code for the module, not for the
# individual packages. In our case, that's less than useful, because the
# module does not, in fact, have overloaded operators.
# See the boot section in the generated code for an explanation of what the
# following code does
#
BOOT:
PL_amagic_generation++;
sv_setsv(
	get_sv( "PlPN::SearchOptions::()", TRUE ),
	&PL_sv_yes	// or &PL_sv_no or &PL_sv_undef
);
(void)newXSproto_portable("PlPN::SearchOptions::()", XS_PlPN_nil, file, "$$$");

=head1 METHODS

=over

=item FindTextZ<>([$text])

Gets or sets the text to be found.

=cut

const wchar_t*
extensions::ISearchOptions::FindText(findText = NULL)
		const wchar_t* findText;
	CODE:
		if (items >= 2)
			THIS->SetFindText(findText);
		RETVAL = THIS->GetFindText();
	OUTPUT:
		RETVAL
	CLEANUP:
		// caller responsible for freeing memory after utf8_2_wide
		if (findText != NULL)
			free((void*)findText);

=item MatchWholeWordZ<>([1|0])

=item MatchCaseZ<>([1|0])

=item UseRegExpZ<>([1|0])

=item SearchBackwardsZ<>([1|0])

=item LoopOKZ<>([1|0])

=item UseSlashesZ<>([1|0])

=item NoCursorMoveZ<>([1|0])

=item ReplaceInSelectionZ<>([1|0])

=item RecurseZ<>([1|0])

=item IncludeHiddenZ<>([1|0])

=item RecurseZ<>([1|0])

=item FoundZ<>([1|0])

Gets or sets the associated boolean option.

C<Fo>C<und> is an indicator of whether the search was successful. It will be
set automatically by the system, but you can, for example, reset it to a
false value and perform the search again.

=cut

bool
extensions::ISearchOptions::MatchWholeWord(matchWholeWord = false)
		bool matchWholeWord;
	CODE:
		if (items >= 2)
			THIS->SetMatchWholeWord(matchWholeWord);
		RETVAL = THIS->GetMatchWholeWord();
	OUTPUT:
		RETVAL

bool
extensions::ISearchOptions::MatchCase(matchCase = false)
		bool matchCase;
	CODE:
		if (items >= 2)
			THIS->SetMatchCase(matchCase);
		RETVAL = THIS->GetMatchCase();
	OUTPUT:
		RETVAL

bool
extensions::ISearchOptions::UseRegExp(useRegExp = false)
		bool useRegExp;
	CODE:
		if (items >= 2)
			THIS->SetUseRegExp(useRegExp);
		RETVAL = THIS->GetUseRegExp();
	OUTPUT:
		RETVAL

=item FindTargetZ<>([$target])

Gets or sets the search target. The target constants are exposed via the
C<:EFindWhere> tag in L<PlPN|PlPN>. These constants are:

=over

=item elwCurrentDoc

=item elwAllDocs

=item elwCurrentProj

=item elwSelection

=back

=cut

extensions::EFindWhere
extensions::ISearchOptions::FindTarget(target = extensions::elwCurrentDoc)
		extensions::EFindWhere target;
	CODE:
		if (items >= 2)
			THIS->SetFindTarget(target);
		RETVAL = THIS->GetFindTarget();
	OUTPUT:
		RETVAL

bool
extensions::ISearchOptions::SearchBackwards(backwards = false)
		bool backwards;
	CODE:
		if (items >= 2)
			THIS->SetSearchBackwards(backwards);
		RETVAL = THIS->GetSearchBackwards();
	OUTPUT:
		RETVAL

bool
extensions::ISearchOptions::LoopOK(loop = false)
		bool loop;
	CODE:
		if (items >= 2)
			THIS->SetLoopOK(loop);
		RETVAL = THIS->GetLoopOK();
	OUTPUT:
		RETVAL

bool
extensions::ISearchOptions::UseSlashes(slashes = false)
		bool slashes;
	CODE:
		if (items >= 2)
			THIS->SetUseSlashes(slashes);
		RETVAL = THIS->GetUseSlashes();
	OUTPUT:
		RETVAL

bool
extensions::ISearchOptions::NoCursorMove(reposition = false)
		bool reposition;
	CODE:
		if (items >= 2)
			THIS->SetNoCursorMove(reposition);
		RETVAL = THIS->GetNoCursorMove();
	OUTPUT:
		RETVAL

=item ReplaceTextZ<>([$text])

Gets or sets the replacement text.

=cut

const wchar_t*
extensions::ISearchOptions::ReplaceText(text = NULL)
		const wchar_t* text;
	CODE:
		if (items >= 2)
			THIS->SetReplaceText(text);
		RETVAL = THIS->GetReplaceText();
	OUTPUT:
		RETVAL
	CLEANUP:
		// caller responsible for freeing memory after utf8_2_wide
		if (text != NULL)
			free((void*)text);

bool
extensions::ISearchOptions::ReplaceInSelection(inSelection = false)
		bool inSelection;
	CODE:
		if (items >= 2)
			THIS->SetReplaceInSelection(inSelection);
		RETVAL = THIS->GetReplaceInSelection();
	OUTPUT:
		RETVAL

=item FileExtsZ<>([$extensions])

Gets or sets the list of file extension filters. C<$extensions> is a
semi-colon separated list of file extensions:

	$uso->FileExts("*.pl;*.pm;*.pod");

DETERMINE FORMAT.

=cut

const wchar_t*
extensions::ISearchOptions::FileExts(extensions = NULL)
		const wchar_t* extensions;
	CODE:
		if (items >= 2)
			THIS->SetFileExts(extensions);
		RETVAL = THIS->GetFileExts();
	OUTPUT:
		RETVAL
	CLEANUP:
		// caller responsible for freeing memory after utf8_2_wide
		if (extensions != NULL)
			free((void*)extensions);

=item SearchPathZ<>([$path])

Gets or sets the search path.

=cut

const wchar_t*
extensions::ISearchOptions::SearchPath(path = NULL)
		const wchar_t* path;
	CODE:
		if (items >= 2)
			THIS->SetSearchPath(path);
		RETVAL = THIS->GetSearchPath();
	OUTPUT:
		RETVAL
	CLEANUP:
		// caller responsible for freeing memory after utf8_2_wide
		if (path != NULL)
			free((void*)path);

bool
extensions::ISearchOptions::Recurse(recurse = false)
		bool recurse;
	CODE:
		if (items >= 2)
			THIS->SetRecurse(recurse);
		RETVAL = THIS->GetRecurse();
	OUTPUT:
		RETVAL

bool
extensions::ISearchOptions::IncludeHidden(hidden = false)
		bool hidden;
	CODE:
		if (items >= 2)
			THIS->SetIncludeHidden(hidden);
		RETVAL = THIS->GetIncludeHidden();
	OUTPUT:
		RETVAL

=item FileSetZ<>([$fileSet])

Gets or sets the file set to search in. The file set constants are exposed
via the C<:EFIFFileSet> tag in L<PlPN|PlPN>. These constants are:

=over

=item ifPath

=item fifSingleFile

=item fifOpenFiles

=item fifActiveProjectFiles

=back

C<$fileSet> defaults to C<fif>C<Path>.

=cut
	
extensions::EFIFFileSet
extensions::ISearchOptions::FileSet(fileSet = extensions::fifPath)
		extensions::EFIFFileSet fileSet;
	CODE:
		if (items >= 2)
			THIS->SetFileSet(fileSet);
		RETVAL = THIS->GetFileSet();
	OUTPUT:
		RETVAL

bool
extensions::ISearchOptions::Found(found = false)
		bool found;
	CODE:
		if (items >= 2)
			THIS->SetFound(found);
		RETVAL = THIS->GetFound();
	OUTPUT:
		RETVAL

=back

=head1 COPYRIGHT and LICENCE

Copyright (c) 2012 Sean Healy. All rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut
